﻿using Abp.Domain.Entities;
using shenghua.Common.CustomValueType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Commodity.Commodities
{
    /// <summary>
    /// 产品购物选项
    /// </summary>
    public class CommodityShoppingOption : Entity, IExtendableObject
    {
        public long CommodityId { get; set; }

        public Money Price { get; set; }

        /// <summary>
        /// 购买单个商品可获得的积分值
        /// </summary>
        public int XPValue { get; set; }

        /// <summary>
        /// 库存量
        /// </summary>
        public int Inventory { get; set; }

        /// <summary>
        /// 最小限购数量，大于等于1
        /// </summary>
        public int MinLimitCount { get; set; }

        /// <summary>
        /// 最大限购数量,0表示不限购
        /// </summary>
        public int MaxLimitCount { get; set; }

        /// <summary>
        /// 图片集
        /// </summary>
        public ValueArray<string> Pictures { get; set; }

        /// <summary>
        /// 销量
        /// </summary>
        public int SalesVolume { get; set; }

        public string ExtensionData { get; set; }

        /// <summary>
        /// 购物选项参数集，多为自定义参数，因为不确定，所以不能写成固定字段
        /// </summary>
        public Dictionary<string, string> ShoppingOptionParameters
        {
            get
            {
                return this.GetData<Dictionary<string, string>>("parameters");
            }
        }

        public void SetShoppingOptionParameters(Dictionary<string, string> parameters)
        {
            this.SetData("parameters", parameters);
        }

        public CommodityShoppingOption()
        {
            Price = new Money();
            SetShoppingOptionParameters(new Dictionary<string, string>());
            Pictures = new ValueArray<string>();
        }

        public bool IsValidCount(int count)
        {
            if(count >= MinLimitCount && count <= MaxLimitCount)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
